{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>clicked</th>\n",
       "      <th>I1</th>\n",
       "      <th>I2</th>\n",
       "      <th>I3</th>\n",
       "      <th>I4</th>\n",
       "      <th>I5</th>\n",
       "      <th>I6</th>\n",
       "      <th>I7</th>\n",
       "      <th>I8</th>\n",
       "      <th>I9</th>\n",
       "      <th>...</th>\n",
       "      <th>C17</th>\n",
       "      <th>C18</th>\n",
       "      <th>C19</th>\n",
       "      <th>C20</th>\n",
       "      <th>C21</th>\n",
       "      <th>C22</th>\n",
       "      <th>C23</th>\n",
       "      <th>C24</th>\n",
       "      <th>C25</th>\n",
       "      <th>C26</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>1382</td>\n",
       "      <td>4</td>\n",
       "      <td>15</td>\n",
       "      <td>2</td>\n",
       "      <td>181</td>\n",
       "      <td>...</td>\n",
       "      <td>e5ba7672</td>\n",
       "      <td>f54016b9</td>\n",
       "      <td>21ddcdc9</td>\n",
       "      <td>b1252a9d</td>\n",
       "      <td>07b5194c</td>\n",
       "      <td>0</td>\n",
       "      <td>3a171ecb</td>\n",
       "      <td>c5c50484</td>\n",
       "      <td>e8b83407</td>\n",
       "      <td>9727dd16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>44</td>\n",
       "      <td>1</td>\n",
       "      <td>102</td>\n",
       "      <td>8</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>...</td>\n",
       "      <td>07c540c4</td>\n",
       "      <td>b04e4670</td>\n",
       "      <td>21ddcdc9</td>\n",
       "      <td>5840adea</td>\n",
       "      <td>60f6221e</td>\n",
       "      <td>0</td>\n",
       "      <td>3a171ecb</td>\n",
       "      <td>43f13e8b</td>\n",
       "      <td>e8b83407</td>\n",
       "      <td>731c3655</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>14</td>\n",
       "      <td>767</td>\n",
       "      <td>89</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>245</td>\n",
       "      <td>...</td>\n",
       "      <td>8efede7f</td>\n",
       "      <td>3412118d</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>e587c466</td>\n",
       "      <td>ad3062eb</td>\n",
       "      <td>3a171ecb</td>\n",
       "      <td>3b183c5c</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>893</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>4392</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1e88c74f</td>\n",
       "      <td>74ef3502</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>6b3a5ca6</td>\n",
       "      <td>0</td>\n",
       "      <td>3a171ecb</td>\n",
       "      <td>9117a34a</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>-1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1e88c74f</td>\n",
       "      <td>26b3c7a7</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>21c9516a</td>\n",
       "      <td>0</td>\n",
       "      <td>32c7478e</td>\n",
       "      <td>b34f3128</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 40 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   clicked  I1   I2  I3  I4    I5  I6  I7  I8   I9  ...        C17        C18  \\\n",
       "0        0   1    1   5   0  1382   4  15   2  181  ...   e5ba7672   f54016b9   \n",
       "1        0   2    0  44   1   102   8   2   2    4  ...   07c540c4   b04e4670   \n",
       "2        0   2    0   1  14   767  89   4   2  245  ...   8efede7f   3412118d   \n",
       "3        0   0  893   0   0  4392   0   0   0    0  ...   1e88c74f   74ef3502   \n",
       "4        0   3   -1   0   0     2   0   3   0    0  ...   1e88c74f   26b3c7a7   \n",
       "\n",
       "         C19        C20        C21        C22        C23        C24  \\\n",
       "0   21ddcdc9   b1252a9d   07b5194c          0   3a171ecb   c5c50484   \n",
       "1   21ddcdc9   5840adea   60f6221e          0   3a171ecb   43f13e8b   \n",
       "2          0          0   e587c466   ad3062eb   3a171ecb   3b183c5c   \n",
       "3          0          0   6b3a5ca6          0   3a171ecb   9117a34a   \n",
       "4          0          0   21c9516a          0   32c7478e   b34f3128   \n",
       "\n",
       "         C25        C26  \n",
       "0   e8b83407   9727dd16  \n",
       "1   e8b83407   731c3655  \n",
       "2          0          0  \n",
       "3          0          0  \n",
       "4          0          0  \n",
       "\n",
       "[5 rows x 40 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "#导入训练集\n",
    "CONTINUOUS_COLUMNS =  [\"I\"+str(i) for i in range(1,14)] # 1-13 inclusive\n",
    "CATEGORICAL_COLUMNS = [\"C\"+str(i) for i in range(1,27)] # 1-26 inclusive\n",
    "LABEL_COLUMN = [\"clicked\"]\n",
    "TRAIN_DATA_COLUMNS = LABEL_COLUMN + CONTINUOUS_COLUMNS + CATEGORICAL_COLUMNS\n",
    "\n",
    "train = pd.read_csv(\"data/train.csv\", header=None)\n",
    "train.columns = TRAIN_DATA_COLUMNS\n",
    "train.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>clicked</th>\n",
       "      <th>I1</th>\n",
       "      <th>I2</th>\n",
       "      <th>I3</th>\n",
       "      <th>I4</th>\n",
       "      <th>I5</th>\n",
       "      <th>I6</th>\n",
       "      <th>I7</th>\n",
       "      <th>I8</th>\n",
       "      <th>I9</th>\n",
       "      <th>I10</th>\n",
       "      <th>I11</th>\n",
       "      <th>I12</th>\n",
       "      <th>I13</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>800000.000000</td>\n",
       "      <td>800000.000000</td>\n",
       "      <td>800000.000000</td>\n",
       "      <td>800000.000000</td>\n",
       "      <td>800000.000000</td>\n",
       "      <td>8.000000e+05</td>\n",
       "      <td>800000.000000</td>\n",
       "      <td>800000.000000</td>\n",
       "      <td>800000.000000</td>\n",
       "      <td>800000.000000</td>\n",
       "      <td>800000.000000</td>\n",
       "      <td>800000.000000</td>\n",
       "      <td>800000.000000</td>\n",
       "      <td>800000.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>0.255895</td>\n",
       "      <td>1.878958</td>\n",
       "      <td>90.995645</td>\n",
       "      <td>16.785155</td>\n",
       "      <td>5.182579</td>\n",
       "      <td>1.803876e+04</td>\n",
       "      <td>91.966901</td>\n",
       "      <td>14.194829</td>\n",
       "      <td>13.423526</td>\n",
       "      <td>102.650386</td>\n",
       "      <td>0.327994</td>\n",
       "      <td>2.431985</td>\n",
       "      <td>0.214099</td>\n",
       "      <td>5.784368</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.436363</td>\n",
       "      <td>7.043450</td>\n",
       "      <td>340.393370</td>\n",
       "      <td>324.918993</td>\n",
       "      <td>8.058630</td>\n",
       "      <td>6.648007e+04</td>\n",
       "      <td>411.870806</td>\n",
       "      <td>57.741705</td>\n",
       "      <td>35.431940</td>\n",
       "      <td>217.223975</td>\n",
       "      <td>0.589100</td>\n",
       "      <td>4.814627</td>\n",
       "      <td>2.929230</td>\n",
       "      <td>33.905975</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-2.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>7.240000e+02</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>2.432000e+03</td>\n",
       "      <td>16.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>36.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>32.000000</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>9.928000e+03</td>\n",
       "      <td>72.000000</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>106.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>7.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>780.000000</td>\n",
       "      <td>18522.000000</td>\n",
       "      <td>65535.000000</td>\n",
       "      <td>507.000000</td>\n",
       "      <td>2.513122e+06</td>\n",
       "      <td>233523.000000</td>\n",
       "      <td>8807.000000</td>\n",
       "      <td>5064.000000</td>\n",
       "      <td>12661.000000</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>133.000000</td>\n",
       "      <td>768.000000</td>\n",
       "      <td>6702.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             clicked             I1             I2             I3  \\\n",
       "count  800000.000000  800000.000000  800000.000000  800000.000000   \n",
       "mean        0.255895       1.878958      90.995645      16.785155   \n",
       "std         0.436363       7.043450     340.393370     324.918993   \n",
       "min         0.000000       0.000000      -2.000000       0.000000   \n",
       "25%         0.000000       0.000000       0.000000       1.000000   \n",
       "50%         0.000000       0.000000       2.000000       3.000000   \n",
       "75%         1.000000       1.000000      32.000000      10.000000   \n",
       "max         1.000000     780.000000   18522.000000   65535.000000   \n",
       "\n",
       "                  I4            I5             I6             I7  \\\n",
       "count  800000.000000  8.000000e+05  800000.000000  800000.000000   \n",
       "mean        5.182579  1.803876e+04      91.966901      14.194829   \n",
       "std         8.058630  6.648007e+04     411.870806      57.741705   \n",
       "min         0.000000  0.000000e+00       0.000000       0.000000   \n",
       "25%         0.000000  7.240000e+02       0.000000       0.000000   \n",
       "50%         2.000000  2.432000e+03      16.000000       3.000000   \n",
       "75%         7.000000  9.928000e+03      72.000000      10.000000   \n",
       "max       507.000000  2.513122e+06  233523.000000    8807.000000   \n",
       "\n",
       "                  I8             I9            I10            I11  \\\n",
       "count  800000.000000  800000.000000  800000.000000  800000.000000   \n",
       "mean       13.423526     102.650386       0.327994       2.431985   \n",
       "std        35.431940     217.223975       0.589100       4.814627   \n",
       "min         0.000000       0.000000       0.000000       0.000000   \n",
       "25%         2.000000       8.000000       0.000000       0.000000   \n",
       "50%         8.000000      36.000000       0.000000       1.000000   \n",
       "75%        20.000000     106.000000       1.000000       2.000000   \n",
       "max      5064.000000   12661.000000       8.000000     133.000000   \n",
       "\n",
       "                 I12            I13  \n",
       "count  800000.000000  800000.000000  \n",
       "mean        0.214099       5.784368  \n",
       "std         2.929230      33.905975  \n",
       "min         0.000000       0.000000  \n",
       "25%         0.000000       0.000000  \n",
       "50%         0.000000       2.000000  \n",
       "75%         0.000000       7.000000  \n",
       "max       768.000000    6702.000000  "
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "C1  = + >  1185 \n",
      "\n",
      "C2  = + >  529 \n",
      "\n",
      "C3  = + >  264473 \n",
      "\n",
      "C4  = + >  103566 \n",
      "\n",
      "C5  = + >  259 \n",
      "\n",
      "C6  = + >  14 \n",
      "\n",
      "C7  = + >  10666 \n",
      "\n",
      "C8  = + >  542 \n",
      "\n",
      "C9  = + >  3 \n",
      "\n",
      "C10  = + >  28255 \n",
      "\n",
      "C11  = + >  4658 \n",
      "\n",
      "C12  = + >  222451 \n",
      "\n",
      "C13  = + >  3058 \n",
      "\n",
      "C14  = + >  26 \n",
      "\n",
      "C15  = + >  8578 \n",
      "\n",
      "C16  = + >  172322 \n",
      "\n",
      "C17  = + >  10 \n",
      "\n",
      "C18  = + >  3763 \n",
      "\n",
      "C19  = + >  1803 \n",
      "\n",
      "C20  = + >  4 \n",
      "\n",
      "C21  = + >  200209 \n",
      "\n",
      "C22  = + >  15 \n",
      "\n",
      "C23  = + >  15 \n",
      "\n",
      "C24  = + >  36845 \n",
      "\n",
      "C25  = + >  69 \n",
      "\n",
      "C26  = + >  27958 \n",
      "\n"
     ]
    }
   ],
   "source": [
    "for name in CATEGORICAL_COLUMNS:\n",
    "    print(name,' = + > ',train[name].unique().size,'\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "KEY_DICT = {'C2':529,'C5':259,'C6':14,'C8':542,'C9':3,'C14':26,'C17':10,'C20':4,'C22':15,'C23':15,'C25':69}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I1 =+> distinct count: 247 ;min: 0 ;mean: 1.8789575 ;median: 0.0 ;max: 780 \n",
      "\n",
      "I2 =+> distinct count: 3915 ;min: -2 ;mean: 90.995645 ;median: 2.0 ;max: 18522 \n",
      "\n",
      "I3 =+> distinct count: 1630 ;min: 0 ;mean: 16.785155 ;median: 3.0 ;max: 65535 \n",
      "\n",
      "I4 =+> distinct count: 192 ;min: 0 ;mean: 5.18257875 ;median: 2.0 ;max: 507 \n",
      "\n",
      "I5 =+> distinct count: 70649 ;min: 0 ;mean: 18038.75820625 ;median: 2432.0 ;max: 2513122 \n",
      "\n",
      "I6 =+> distinct count: 3729 ;min: 0 ;mean: 91.96690125 ;median: 16.0 ;max: 233523 \n",
      "\n",
      "I7 =+> distinct count: 1249 ;min: 0 ;mean: 14.19482875 ;median: 3.0 ;max: 8807 \n",
      "\n",
      "I8 =+> distinct count: 324 ;min: 0 ;mean: 13.42352625 ;median: 8.0 ;max: 5064 \n",
      "\n",
      "I9 =+> distinct count: 2953 ;min: 0 ;mean: 102.65038625 ;median: 36.0 ;max: 12661 \n",
      "\n",
      "I10 =+> distinct count: 9 ;min: 0 ;mean: 0.32799375 ;median: 0.0 ;max: 8 \n",
      "\n",
      "I11 =+> distinct count: 121 ;min: 0 ;mean: 2.431985 ;median: 1.0 ;max: 133 \n",
      "\n",
      "I12 =+> distinct count: 147 ;min: 0 ;mean: 0.21409875 ;median: 0.0 ;max: 768 \n",
      "\n",
      "I13 =+> distinct count: 383 ;min: 0 ;mean: 5.7843675 ;median: 2.0 ;max: 6702 \n",
      "\n"
     ]
    }
   ],
   "source": [
    "for name in CONTINUOUS_COLUMNS:\n",
    "    print(name,'=+> distinct count:',train[name].unique().size,';min:',train[name].min(),';mean:',train[name].mean(),';median:',train[name].median(),';max:',train[name].max(),'\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "boundaries_dict = {'I1':[2,247],'I4':[2,5,192],'I10':[1,2,3,4,5,6,7],'I11':[1,2,121],'I12':[1,147]}"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
